package com.jy.rhin.infra.repo.notfication.topic.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jy.rhin.domain.notification.topic.entity.EnumFilterType;
import com.jy.rhin.domain.notification.topic.entity.TopicQueryFilterVO;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author WeiQ
 * @date 2022/6/28 17:12
 */
@Data
@TableName("t_notification_topic_query_filter")
@NoArgsConstructor
public class TopicQueryFilterPO {

    public TopicQueryFilterPO(TopicQueryFilterVO topicQueryFilter, String topicExp, String queryExp) {
        this.topicExp = topicExp;
        this.queryExp = queryExp;
        this.filterName = topicQueryFilter.getFilterName();
        this.filterExp = topicQueryFilter.getFilterExp();
        this.targetPath = topicQueryFilter.getTargetPath();
        this.sourcePath = topicQueryFilter.getSourcePath();
        this.compareExp = topicQueryFilter.getCompareExp();
        this.filterType = topicQueryFilter.getFilterType().name();
        this.filterCode = topicQueryFilter.getFilterCode();
    }

    public TopicQueryFilterVO toDO() {
        TopicQueryFilterVO filterVo = new TopicQueryFilterVO();
        filterVo.setFilterName(this.filterName);
        filterVo.setFilterExp(this.filterExp);
        filterVo.setTargetPath(this.targetPath);
        filterVo.setSourcePath(this.sourcePath);
        filterVo.setCompareExp(this.compareExp);
        filterVo.setFilterType(EnumFilterType.valueOf(this.filterType));
        filterVo.setFilterCode(this.filterCode);
        return filterVo;
    }

    @TableId
    private Long id;
    /**
     * 主题表达式
     */
    @TableField("topic_exp")
    private String topicExp;
    /**
     * 预存查询函数表达式
     */
    @TableField("query_exp")
    private String queryExp;
    /**
     * 过滤条件名称
     */
    @TableField("filter_name")
    private String filterName;
    /**
     * 过滤条件表达式
     */
    @TableField("filter_exp")
    private String filterExp;
    /**
     * 过滤条件JSON对象jsonPath
     */
    @TableField("target_path")
    private String targetPath;
    /**
     * 过滤条件字段webService对象路径
     */
    @TableField("source_path")
    private String sourcePath;
    /**
     * 比较表达式 LT:<  LE:<=   EQ:=  GE:>=  GT:>
     */
    @TableField("compare_exp")
    private String compareExp;
    /**
     * 过滤条件值域类型
     */
    @TableField("filter_type")
    private String filterType;
    /**
     * 过滤条件值域code
     */
    @TableField("filter_code")
    private String filterCode;
}
